import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

export default new Router({
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
      redirect:'/home',
      children:[
        {
          path: '/tree',
          name: 'tree',
          component: resolve => require(['@/pages/tree/index'],resolve),
        },
        {
          path: '/home',
          name: 'home',
          component: resolve => require(['@/pages/home/index'],resolve),
        },{
          path:'/classify',
          name:'classify',
          component:resolve => require(['@/pages/home/classify'],resolve)
        },{
          path:'/detail',
          name:'detail',
          component:resolve => require(['@/pages/home/detail'],resolve)
        },{
          path:'/car',
          name:'car',
          component:resolve => require(['@/pages/car/index'],resolve)
        },{
          path:'/settlement',
          name:'settlement',
          component:resolve => require(['@/pages/car/settlement'],resolve)
        },{
          path:'/settlepay',
          name:'settlepay',
          component:resolve => require(['@/pages/car/settlepay'],resolve)
        },{
          path:'/settleorder',
          name:'settleorder',
          component:resolve => require(['@/pages/car/settleorder'],resolve)
        },{
          path:'/mine',
          name:'mine',
          component:resolve => require(['@/pages/mine/index'],resolve),
          redirect:'/personal',
          children:[
            {
              path:'/personal',
              name:'personal',
              meta:{state:1},
              component:resolve => require(['@/pages/mine/component/personal'],resolve),
            },
            {
              path:'/distributor',
              name:'distributor',
              meta:{state:1},
              component:resolve => require(['@/pages/mine/component/distributor'],resolve),
            },
            {
              path:'/address',
              name:'address',
              meta:{state:2},
              component:resolve => require(['@/pages/mine/component/address'],resolve),
            },
            {
              path:'/purorder',
              name:'purorder',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/purorder'],resolve),
            },
            {
              path:'/orderagain',
              name:'orderagain',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderagain'],resolve),
            },
            {
              path:'/ordercomment',
              name:'ordercomment',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/ordercomment'],resolve),
            },
            {
              path:'/orderfinish',
              name:'orderfinish',

              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderfinish'],resolve),
            }, {
              path:'/orderline',
              name:'orderline',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderline'],resolve),
            },
            {
              path:'/orderpay',
              name:'orderpay',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderpay'],resolve),
            },
            {
              path:'/ordercancel',
              name:'ordercancel',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/ordercancel'],resolve),
            },
            {
              path:'/orderstart',
              name:'orderstart',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderstart'],resolve),
            },
            {
              path:'/orderback',
              name:'orderback',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/orderback'],resolve),
            },
            {
              path:'/pvmine',
              name:'pvmine',
              meta:{state:7},
              component:resolve => require(['@/pages/mine/component/pvmine'],resolve),
            },
            {
              path:'/pvmineo',
              name:'pvmineo',
              meta:{state:7},
              component:resolve => require(['@/pages/mine/component/pvmineo'],resolve),
            },
            {
              path:'/pvminet',
              name:'pvminet',
              meta:{state:7},
              component:resolve => require(['@/pages/mine/component/pvminet'],resolve),
            },
            {
              path:'/pvminef',
              name:'pvminef',
              meta:{state:7},
              component:resolve => require(['@/pages/mine/component/pvminef'],resolve),
            },
            {
              path:'/pvmineth',
              name:'pvmineth',
              meta:{state:7},
              component:resolve => require(['@/pages/mine/component/pvmineth'],resolve),
            },
            {
              path:'/myCoupon',
              name:'myCoupon',
              meta:{state:4},
              component:resolve => require(['@/pages/mine/component/coupon'],resolve),
            },
            {
              path:'/myCollect',
              name:'myCollect',
              meta:{state:10},
              component:resolve => require(['@/pages/mine/component/collect'],resolve),
            },
            {
              path:'/goodComment',
              name:'goodComment',
              meta:{state:3},
              component:resolve => require(['@/pages/mine/component/comment'],resolve),
            },
            {
              path:'/pvDetails',
              name:'pvDetails',
              meta:{state:5},
              component:resolve => require(['@/pages/mine/component/pv_details'],resolve),
            },
            {
              path:'/pvDetailss',
              name:'pvDetailss',
              meta:{state:5},
              component:resolve => require(['@/pages/mine/component/pv_detailss'],resolve),
            },
            {
              path:'/pvteam',
              name:'pvteam',
              meta:{state:8},
              component:resolve => require(['@/pages/mine/component/pv_team'],resolve),
            },
            {
              path:'/pvteamo',
              name:'pvteamo',
              meta:{state:8},
              component:resolve => require(['@/pages/mine/component/pv_teamo'],resolve),
            },
            {
              path:'/pvteamt',
              name:'pvteamt',
              meta:{state:8},
              component:resolve => require(['@/pages/mine/component/pv_teamt'],resolve),
            },
            {
              path:'/pvteamth',
              name:'pvteamth',
              meta:{state:8},
              component:resolve => require(['@/pages/mine/component/pv_teamth'],resolve),
            },
            {
              path:'/team_member',
              name:'team_member',
              meta:{state:9},
              component:resolve => require(['@/pages/mine/component/team_member'],resolve),
            },
            {
              path:'/team_member_detail',
              name:'team_member_detail',
              meta:{state:9},
              component:resolve => require(['@/pages/mine/component/team_m_detail'],resolve),
            },
            {
              path:'/pvjob',
              name:'pvjob',
              meta:{state:6},
              component:resolve => require(['@/pages/mine/component/pv_job'],resolve),
            },
          ]
        },{
          path:'/fictitiousOrderagain',
          name:'fictitiousOrderagain',
          component:resolve => require(['@/pages/fictitious/orderagain'],resolve),
        },{
          path:'/fictitiousOrderline',
          name:'fictitiousOrderline',
          component:resolve => require(['@/pages/fictitious/orderline'],resolve),
        },{
          path:'/fictitiousOrderpay',
          name:'fictitiousOrderpay',
          component:resolve => require(['@/pages/fictitious/orderpay'],resolve),
        },{
          path:'/footdetail',
          name:'footdetail',
          component:resolve => require(['@/pages/home/footdetail'],resolve)
        },{
          path:'/footlian',
          name:'footlian',
          component:resolve => require(['@/components/lian'],resolve)
        },{
          path:'/paysuccess',
          name:'paysuccess',
          component:resolve => require(['@/pages/car/paySuccess'],resolve)
        },{
          path:'/payfail',
          name:'payfail',
          component:resolve => require(['@/pages/car/payFail'],resolve)
        },{
          path:'/pay',
          name:'pay',
          component:resolve => require(['@/pages/car/pay'],resolve)
        },{
          path:'/search',
          name:'search',
          component:resolve => require(['@/pages/home/search'],resolve)
        }
      ]
    },{
      path:'/login',
      name:'login',
      component:resolve => require(['@/pages/login/index'],resolve)
    },{
      path:'/regist',
      name:'regist',
      component:resolve => require(['@/pages/login/regist'],resolve)
    },{
      path:'/forget',
      name:'forget',
      component:resolve => require(['@/pages/login/forget'],resolve)
    },
    {
      path:'/forgetone',
      name:'forgetone',
      component:resolve => require(['@/pages/login/forgetone'],resolve)
    },
    {
      path:'/forgettwo',
      name:'forgettwo',
      component:resolve => require(['@/pages/login/forgettwo'],resolve)
    },{
      path:'/good',
      name:'good',
      component:resolve => require(['@/pages/car/good'],resolve)
    },{
      path: '/newest',
      name: 'newest',
      component: resolve => require(['@/pages/new/index'],resolve),
    }
  ]
})


const originalPush = Router.prototype.push
  Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}